/*
 * @Author: ZhanXie
 * @Date: 2019-11-27 10:08:35
 * @LastEditors  : ZhanXie
 * @LastEditTime : 2019-12-30 16:59:48
 * @Description: user 控制层
 * @FilePath: /node-demo/blog-origin/src/controller/user.js
 */
const { exec, escape } = require('../db/mysql')
const { genPassWord } = require('../util/cryp')

const login = async (username, password) => {
  username = escape(username)
  password = genPassWord(password) // 生成加密密码
  password = escape(password) // 防止 sql 注入

  const sql = `select username, realname from users where username=${username} and password=${password}`
  const rows = await exec(sql)
  return rows[0] || {}
}

module.exports = {
  login
}